package cm309.BookingSystem.FM;

	import java.io.IOException;
	import java.sql.Connection;
	import java.sql.PreparedStatement;
	import java.sql.SQLException;

	import javax.servlet.RequestDispatcher;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;

	public class  factilitiesAddHandler extends HttpServlet {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException {
			int id = Integer.valueOf(req.getParameter("id"));
			String name = req.getParameter("name");
			int status = Integer.valueOf(req.getParameter("status"));
			try {
				Connection conn = null;
				try {
					conn = factilitiesDao.getConnection();
					PreparedStatement ps;
					ps = conn.prepareStatement("INSERT INTO BK_FM_Factilites VALUES(?,?,?)");
					ps.setInt(1, id);
					ps.setString(2, name);
					ps.setInt(3, status);

					int count = ps.executeUpdate();
					conn.commit();
					RequestDispatcher dispatcher = req.getRequestDispatcher("FactilitesResult.html");
					dispatcher.forward(req, resp);
				}catch (SQLException e) {
					conn.rollback();
					e.printStackTrace();
					
				}finally {
					conn.close();
				}
				
			}catch (Exception e){
				e.printStackTrace();
			}			
		}

	}
